﻿<div class="form-group col-12 col-sm-6">
    <Select TValue="string" Items="@Items3" 
            OnSelectedItemChanged="@OnCascadeBindSelectClick">
    </Select>
</div>
<div class="form-group col-12 col-sm-6">
    <Select @ref="Select2" TValue="string" Items="@Items2">
    </Select>
</div>

@code {
    private readonly List<SelectedItem> _item2 = new List<SelectedItem>();

    private IEnumerable<SelectedItem> Items2 => _item2;

    /// <summary>
    /// 获得 默认数据集合
    /// </summary>
    private readonly IEnumerable<SelectedItem> Items3 = new SelectedItem[]
    {
        new SelectedItem ("", "请选择 ..."),
        new SelectedItem ("Beijing", "北京"),
        new SelectedItem ("Shanghai", "上海"),
        new SelectedItem ("Hangzhou", "杭州")
    };

    private Select<string> Select2;

    /// <summary>
    /// 级联绑定菜单
    /// </summary>
    /// <param name="item"></param>
    protected void OnCascadeBindSelectClick(SelectedItem item)
    {
        _item2.Clear();
        if (item.Value == "Beijing")
        {
            _item2.AddRange(new SelectedItem[]
            {
                new SelectedItem("1","朝阳区"),
                new SelectedItem("2","海淀区"),
            });
        }
        else if (item.Value == "Shanghai")
        {
            _item2.AddRange(new SelectedItem[]
            {
                new SelectedItem("1","静安区"),
                new SelectedItem("2","黄浦区"),
            });
        }
        Select2?.SetItems(_item2);
        return Task.CompletedTask;
    }
}
